<template>
  <div>
    <el-button type="primary"  size="mini" class="back" @click="$router.push('/promoteList')">返回推广列表</el-button>
    <el-card>
      <el-form ref="form" :model="form" class="form" :inline="true" size="mini">
        <el-form-item label="店铺ID/昵称" class="name">
          <el-input v-model.number="input" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="开店日期">
          <el-date-picker
            v-model="time"
             type="daterange"
            value-format="timestamp"
             :clearable="false"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            @change="change"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-row type="flex" justify="end">
        <el-col :span="6">
          <el-button type="primary" size="small" @click="search">查询</el-button>
          <el-button size="small"  @click="resetForm()">重置</el-button>
        </el-col>
      </el-row>
    </el-card>
    <p><span class="num">推广店铺数量：{{promoteshop}}</span> <span>推广收益金额：{{get}}元</span></p>
    <el-card>
      <el-table :data="tableData" row-key="id" class="customer-table">
        <el-table-column label="店铺ID" prop="shopId" align="center" />
        <el-table-column label="店铺名称" prop="shopName" align="center" />
        <el-table-column label="店铺地址" prop="shopAddress" align="center" />
        <el-table-column label="店铺联系电话" prop="shopPhone" align="center" />
        <el-table-column label="推广开店日期" align="center" >
           <template slot-scope="{row}">
              <span>{{row.time|formatDate }}</span>
            </template>
        </el-table-column>
        <el-table-column label="推广收益" prop="shopGet" align="center" >
           <template slot-scope="{row}">
              <span>{{row.shopGet }} 元</span>
            </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="center" align="middle" style="height: 60px">
        <el-pagination
           :current-page="page.page"
            :page-size="page.size"
            :total="page.total"
            :page-sizes="[2, 3, 5, 10]"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        >
        </el-pagination>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import { getDetailList } from '@/api/promoteList.js'
import { queryFn } from '@/utils'// 多选项查询
export default {
  data () {
    return {
      id: '',
      time: '',
      input: '',
      form: {
        time_gte: '',
        time_lte: ''
      },
      page: {
        page: 1,
        size: 5,
        total: 12
      },
      tableData: []
    }
  },
  created () {
    this.id = this.$route.query.id
    // console.log(this.id)
    this.getDetailList()
  },
  computed: {
    promoteshop () {
      return this.tableData.length
    },
    get () {
      return this.tableData.reduce((sum, obj) => sum + obj.shopGet, 0)
    }
  },
  methods: {
    // 根据id获取列表数据
    async getDetailList () {
      const { data } = await getDetailList(this.id)
      console.log(data)
      this.tableData = data
      this.page.total = data.length
    },
    // 查询
    async search () {
      const obj = queryFn(this.form)
      console.log(obj)
      // 判断输入内容
      if (typeof this.input === 'number') {
        obj.shopId = this.input
        console.log(obj)
      } else if (typeof this.input === 'string') {
        obj.shopName = this.input
        console.log(obj)
      }
      const { data } = await getDetailList(this.id, obj)
      console.log(data)
      this.tableData = data
      this.page.total = this.tableData.length
      this.input = null
      this.time = []
    },
    // 日期改变
    change (v) {
      // console.log(v)
      if (!v) return
      this.form.time_gte = v[0]
      this.form.time_lte = v[1]
    },
    // 改变页面size
    async  handleSizeChange (newsize) {
      this.page.size = newsize
      const { data } = await getDetailList(this.id, {
        _page: this.page.page,
        _limit: this.page.size
      })
      this.tableData = data
    },
    async  handleCurrentChange (newpage) {
      this.page.page = newpage
      // console.log(newpage)
      const { data } = await getDetailList(this.id, {
        _page: this.page.page,
        _limit: this.page.size
      })
      this.tableData = data
      this.resetForm()
    },
    // 重置
    resetForm () {
      this.form.shopName = ''
      this.time = []
      this.getDetailList()
    }
  }
  // filters: {
  //   formatDate: function (value) {
  //     console.log(value)
  //     return moment(value).format('YYYY-MM-DD')
  //   }

  // }
}
</script>

<style lang="less" scoped>
.form {
  box-sizing: border-box;
}
/deep/.customer-table th {
  border: none;
  // background-color: rgb(170, 56, 56);
  color: white;
  // border-radius: 5px;
}
.customer-table /deep/ th.el-table__cell.is-leaf {
  background-color: rgb(98, 131, 240);

  border: none;
}
// .el-table {
//   // background-color: rgb(71, 100, 138);
// }
.customer-table /deep/ .el-table__row > td {
  border: none;
}
.customer-table /deep/ .el-table__row > td {
  border: none;
}
.el-button + .el-button {
  margin-left: 30px;
}
.el-form--inline .el-form-item {
  margin-right: 120px;
}
.customer-table th {
  border: none;
}
.customer-table td,
.customer-table th.is-leaf {
  border: none;
}
// 表格最外边框
.el-table--border,
.el-table--group {
  border: none;
}
// 头部边框
.customer-table thead tr th.is-leaf {
  border: 1px solid #ebeef5;
  border-right: none;
}
.customer-table thead tr th:nth-last-of-type(2) {
  border-right: 1px solid #ebeef5;
}
// 表格最外层边框-底部边框
.el-table--border::after,
.el-table--group::after {
  width: 0;
}
.customer-table::before {
  width: 0;
}
.customer-table .el-table__fixed-right::before,
.el-table__fixed::before {
  width: 0;
}
// 表格有滚动时表格头边框
.el-table--border th.gutter:last-of-type {
  border: 1px solid #ebeef5;
  border-left: none;
}
.back{
  margin-bottom: 30px;
}.num{
  margin-right: 30px;
}
</style>
